<template>
	<view class="wrap-container">
		<view>
			<uni-nav-bar
				fixed
				title="活动报名"
				status-bar
				background-color="#2163e0"
				color="#fff" />
		</view>
		<view class="form">
			<uni-forms ref="baseForm" :rules="rules" :modelValue="baseFormData">
				<uni-forms-item label="姓名" required name="partyMemberName">
					<uni-easyinput
						v-model="baseFormData.partyMemberName"
						placeholder="请输入姓名" />
				</uni-forms-item>
				<uni-forms-item label="手机号" required name="partyMemberPhone">
					<uni-easyinput
						v-model="baseFormData.partyMemberPhone"
						placeholder="请输入手机号" />
				</uni-forms-item>
				<uni-forms-item label="单位" required name="partyMemberDept">
					<uni-easyinput
						v-model="baseFormData.partyMemberDept"
						placeholder="请输入单位" />
				</uni-forms-item>
			</uni-forms>
			<view class="btn">
				<button type="primary" @click="submit('baseForm')">提交</button>
			</view>
		</view>
	</view>
</template>

<script>
import api from "../../api/api";
export default {
	onLoad(options) {
		this.baseFormData.dynamicId = uni.getStorageSync("partySignEvent").id;
	},
	data() {
		return {
			baseFormData: {},
			rules: {
				partyMemberName: {
					rules: [
						{
							required: true,
							errorMessage: "姓名不能为空",
						},
					],
				},
				partyMemberPhone: {
					rules: [
						{
							required: true,
							errorMessage: "电话不能为空",
						},
					],
				},
				partyMemberDept: {
					rules: [
						{
							required: true,
							errorMessage: "单位不能为空",
						},
					],
				},
			},
		};
	},
	methods: {
		back() {},
		submit(ref) {
			this.$refs[ref]
				.validate()
				.then(() => {
					api.bmdb(this.baseFormData).then((e) => {
						if (e.data.success) {
							uni.showToast({
								title: e.data.message,
							});
							this.baseFormData = {};
							uni.navigateTo({
								url: "/pages/component/signsuccess?msg="+e.data.message,
							});
						} else {
							uni.showToast({
								title: e.data.message,
							});
						}
					});
				})
				.catch((err) => {
					console.log("err", err);
				});
		},
	},
	mounted() {},
};
</script>

<style lang="scss" scoped>
.warp-content {
	display: flex;
	justify-content: space-around;
	margin: 10px auto;
	height: 40px;
	line-height: 40px;
	::v-deep.uni-easyinput__content {
		width: 100%;
	}
}
.form {
	width: 80%;
	margin: 10px auto;
	.btn {
		margin: auto;
		width: 60%;
	}
}
</style>
